<template>
    <div class="login">
        <div class="login_content">
            <div class="login_content_left"></div>
            <div class="login_content_right">
                <el-form ref="AccountFrom" :model="account" :rules="rules" label-position="left" label-width="0px" class="login_form">
                    <h3 class="login_title">登录中心</h3>
                    <el-form-item prop="username">
                        <el-input type="text" v-model="account.username" auto-complete="off" placeholder="用户名" autofocus="autofocus" clearable @keyup.enter.native="next"></el-input>
                    </el-form-item>
                    <el-form-item prop="password" >
                        <el-input type="password" v-model="account.password" auto-complete="off" placeholder="密码" ref="autofocus_pwd" @keyup.enter.native="handleLogin"></el-input>
                        <!-- <el-button type="text" class="findPassword" @click.native="findPassword">忘记密码</el-button> -->
                    </el-form-item>
                    <el-form-item style="width:100%;">
                        <el-button type="primary" class="submit_button" @click.native.prevent="handleLogin" :loading="loading">登录</el-button>
                    </el-form-item>
                </el-form>
            </div>
        </div>
    </div>
</template>
<script>
    import http from '@/api/login'
    import httpApi from '@/api/login'
    import globalApi from '@/api/global'
    import customerApi from '@/api/customer'
    export default {
        data() {
            return {
                loading: false,
                account: {
                    username: 'admin',
                    password: 'admin'
                },
                rules: {
                    username: [
                        {required: true, message: '请输入账号', trigger: 'blur'},
                        //{ validator: validaePass }
                    ],
                    password: [
                        {required: true, message: '请输入密码', trigger: 'blur'},
                        //{ validator: validaePass2 }
                    ]
                },
            };
        },
        methods: {
            findPassword(){
                this.$router.push({ path: "/password" });
            },
            next(){
                this.$refs.autofocus_pwd.focus();
            },
            handleLogin(){
                this.$refs.AccountFrom.validate((valid) => {
                    if (valid) {
                        console.log('valid:',valid);
                        //this.loading = true;
                        //请求接口
                        httpApi.login(this.account).then(res=>{
                            console.log('res:',res);
                            //this.loading = false;
                            document.title = `${res.data.school || '新韦博英语'}-CRM系统`;
                            sessionStorage.setItem('user',JSON.stringify(res.data));
                            sessionStorage.setItem('access_token',res.access_token);
                            globalApi.getBasicConfig().then(data => {
                                sessionStorage.setItem('basicConfig',JSON.stringify(data.data));
                            })
                            this.$router.push({ path: "/" }); 
                        });

                    }
                })
            }
        }
    }
</script>

<style lang="scss" scoped>
    .login{
        width: 100%;
        height: 100%;
        display: flex;
        justify-content: center;
        align-items: center;
        flex-wrap: nowrap;
        //background: url('~@/assets/images/login/bg.png') no-repeat;
        background: url('https://gaoxiaocrm.oss-cn-hangzhou.aliyuncs.com/vue/login/bg.png') no-repeat;
        background-size: 100% 100%;
        overflow: auto;
        &_content{
            display: flex;
            width: 776px;
            height: 424px;
            &_left{
                width: 466px;
                height: 424px;
                background: url('https://gaoxiaocrm.oss-cn-hangzhou.aliyuncs.com/vue/login/login-left.jpg') no-repeat;
                background-size: 100% 100%;
                position: relative;
                
            }
            &_right{
                flex: 1;
                background: #fff;
                min-width: 340px;
                .login_form{
                    margin: 80px 16.12% 20px;
                    .login_title{
                        font-size: 22px;
                        line-height: 80px;
                        color: #1796EB;
                        letter-spacing: 2px;
                        font-weight: 400;
                    }
                    .submit_button{
                        width:100%;
                        height:40px;
                        font-size:16px;
                        letter-spacing:4px;
                    }
                }
            }
        }
    }
    @media (min-width: 1660px) {
        .login{
            &_content{
                display: flex;
                width: 81%;
                height: 78%;
                margin: 30px;
                &_left{
                    width: 60%;
                    height: 100%;
                }
                &_right{
                    flex: 1;
                    background: #fff;
                    min-width: 340px;
                    .login_form{
                        margin: 188px 16.12%;
                        .login_title{
                            font-size: 26px;
                            line-height: 110px;
                            color: #1796EB;
                            letter-spacing: 2px;
                            font-weight: 400;
                        }
                        .submit_button{
                            width:100%;
                            height:62px;
                            font-size:26px;
                            letter-spacing:4px;
                        }
                    }
                }
            }
        }
    }
</style>

<style lang="scss">
@media (min-width: 1660px) {
    .login{
        .el-form-item{
            height: 62px;
            margin-bottom: 30px;
            &>.el-form-item__content{
                height: 62px;
                &>.el-input{
                    height: 62px;
                    &>.el-input__inner{
                        height: 62px;
                        font-size: 18px;
                    }
                }
            }
            .findPassword{
                position: absolute;
                top: 0px;
                right: 10px;
                bottom: 0px;
            }
        }
        .submit_button{
            width:100%;
            height:62px;
            font-size:24px;
            letter-spacing:4px;
        }
    }
}
</style>
